from flask import Flask,render_template
from flask_wtf import FlaskForm
from wtforms import StringField,PasswordField,SubmitField
from wtforms.validators import DataRequired,Length,EqualTo

app = Flask(__name__)

app.secret_key = 'jodjaidjasdkaj'
class RegisterForm(FlaskForm):
    username = StringField(label='用户名：',render_kw={'required':False},
                           validators=[DataRequired(message='用户名不能为空'),Length(3,15,message='长度应为3-15字符')])
    password = PasswordField(label='密码：',render_kw={'required':False},
                             validators=[DataRequired(message='密码不能为空')])
    password2 = PasswordField(label='确认密码：',render_kw={'required':False},
                              validators=[DataRequired(message='密码不能为空'),EqualTo('password',message='两次密码不一致')])
    submit = SubmitField('注册')

@app.route('/register',methods = ['GET','POST'])
def register():
    form = RegisterForm()
    if form.validate_on_submit():
        return '注册成功！'
    return render_template('register_wtf.html',form=form)

if __name__ == '__main__':
    app.run()